package selfview.sufutian.com.myapplication;

import android.app.Activity;
import android.os.Bundle;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.ScrollView;


import androidx.annotation.Nullable;

import selfview.sufutian.com.myapplication.draw2d.SubtitleTextView;
import selfview.sufutian.com.myapplication.draw2d.TextReaderView;

/**
 * Created by sufutian on 2018/10/11.
 */

public class TextReaderActivity extends Activity {

    private int startPosition = 0;
    private int endPosition = 10;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text_read);
        RelativeLayout addRl = (RelativeLayout) findViewById(R.id.add_rl);
        final SubtitleTextView justifyTextView = (SubtitleTextView) findViewById(R.id.just_view);
        TextReaderView textReaderView = new TextReaderView(this);
        final ScrollView scrollView = (ScrollView) findViewById(R.id.scroll);
        addRl.addView(textReaderView);
        justifyTextView.refreshShowContent(startPosition, endPosition);
        findViewById(R.id.refresh_content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startPosition += 10;
                endPosition = startPosition + 10;
                justifyTextView.refreshShowContent(startPosition, endPosition);
                int currentY = justifyTextView.getCurrentY();
                int halfHeight = scrollView.getHeight() / 2;
                if (currentY > halfHeight) {
                    scrollView.smoothScrollTo(0, currentY - halfHeight);
                }
            }
        });
    }
}
